home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
LOGIC Apps
/
Logic-APPLE_II_APPS.iso
/
pc
/
LOGIC Apple II 5.25" Library - DOS Part 3
/
DOS073.dsk
/
FOURIER TRANSFORM HIRES.bas
< prev
next >
Wrap
BASIC Source File
|
2012-02-16
|
3KB
|
130 lines
0 PRINT "HI-RES FAST FOURIER TRANSFORM"
1 PRINT " BY BILL JACOBS"
2 PRINT " BASED ON AN ARTICLE BY W. WAGGENER EDN OCT.5 1978"
3 PRINT "WILL RUN THE FORWARD IE. TIME TO FREQ. OR INVERSE IE. FREQ. TO TIME"
5 PRINT "ENTER 0 FOR FORWARD OR 1 FOR INVERSE"
6 INPUT D
10 DIM X(1025,2),R(202),PH(202)
20 INPUT "ENTER M WHERE NO. OF POINTS=2^M ";M
30 N = 2 ^M
31 PRINT "DO YOU WISH TO ENTER DATA IN TABULAR FORM (0) OR ANALYTIC (1)?"
32 INPUT S
33 IF S = 1 GOTO 200
35 PRINT "INPUT DATA ARRAY"
40 FOR I = 1 TO N
44 PRINT "POINT ";I
45 INPUT X(I,0)
50 NEXT I
55 PRINT "THE DATA ARRAY IS"
60 FOR I = 1 TO N
70 PRINT I,X(I,0)
80 NEXT I
90 PRINT "CALCULATION IN PROGRESS"
110 GOSUB 550
112 PRINT "USE PDL(0) TO CONTROL THE LISTING"
113 PRINT "PRESS SPACE TO PRINT TABLE"
114 WAIT -16384,128
115 PRINT "THE TRANSFORMED DATA IS"
116 PRINT "# REAL IMAG."
118 Q = N/2.56
120 FOR I = 1 TO N
122 FOR Y = 1 TO PDL(0) *10: NEXT Y
130 PRINT I -1;" ";X(I,0);" ";X(I,1)
135 NEXT I
139 INPUT "DO YOU WISH A PLOT?";A$
141 IF A$ = "N" GOTO 5000
142 PRINT "THE PLOT IS OF THE MAGNITUDE (NORMALIZED) IN SOLID AND THE PHASE"
143 PRINT "THE PHASE IS ON A GRID OF THREE LINES THE TOP IS +180 DEG. THE MID IS 0 DEG. THE THIRD IS -180 DEG."
144 PRINT "PRESS SPACE TO CONTINUE"
145 WAIT -16384,128
146 PRINT "CALCULATION IN PROGRESS"
147 KH = 25/P1
148 FOR I = 1 TO Q
151 R(I) = SQR(X(I,0) *X(I,0) +X(I,1) *X(I,1))
153 IF R(I) <T GOTO 157
155 T = R(I)
157 IF X(I,0) = 0 THEN X(I,0) = 1E -6
159 PH(I) = ATN(X(I,1)/X(I,0))
161 IF X(I,0) > = 0 GOTO 169
163 IF X(I,1) > = 0 THEN PH(I) = P1 +PH(I): GOTO 169
167 PH(I) = -P1 +PH(I)
169 PH(I) = PH(I) *KH
171 NEXT I
173 GOTO 2000
200 PRINT "USE LINES 210 THRU 400 TO ENTER FUNCTION AS X(I,0) FOR THE REAL PART AND X(I,1) FOR THE IMAGINARY PART"
202 PRINT "WHEN YOU HAVE COMPLETED YOUR ENTRY TYPE (GOTO 210)TO START THE PROGRAM"
205 END
210 PRINT "CALCULATION IN PROGRESS"
220 FOR I = 1 TO 2
230 X(I,0) = 1
250 NEXT I
401 GOTO 110
550 N = 2 ^M
570 N2 = N/2
580 N1 = N -1
590 J = 1
600 FOR I = 1 TO N1
610 IF I > = J THEN 680
630 T1 = X(J,0)
640 T2 = X(J,1)
650 X(J,0) = X(I,0)
655 X(J,1) = X(I,1)
660 X(I,0) = T1
670 X(I,1) = T2
680 K = N2
690 IF K > = J THEN 730
700 J = J -K
710 K = K/2
720 GOTO 690
730 J = J +K
740 NEXT I
760 S1 = -1
770 IF D = 0 THEN 790
780 S1 = 1
790 P1 = 3.1415926535898
800 FOR L = 1 TO M
810 L1 = 2 ^L
820 L2 = L1/2
830 U1 = 1
840 U2 = 0
850 W1 = COS(P1/L2)
860 W2 = S1 * SIN(P1/L2)
870 FOR J = 1 TO L2
880 FOR I = J TO N STEP L1
890 I1 = I +L2
900 V1 = (X(I1,0) *U1 -X(I1,1) *U2)
910 V2 = (X(I1,1) *U1 +X(I1,0) *U2)
920 X(I1,0) = X(I,0) -V1
930 X(I1,1) = X(I,1) -V2
940 X(I,0) = X(I,0) +V1
950 X(I,1) = X(I,1) +V2
960 NEXT I
975 U3 = U1
976 U4 = U2
980 U1 = (U3 *W1 -U4 *W2)
990 U2 = (U4 *W1 +U3 *W2)
1000 NEXT J
1010 NEXT L
1020 IF D = 1 THEN 1060
1030 FOR I = 1 TO N
1040 X(I,0) = X(I,0)/N
1045 X(I,1) = X(I,1)/N
1050 NEXT I
1060 RETURN
1122 FOR Y = 1 TO PDL(0) *10: NEXT Y
2000 Z = 190/T
2010 C = 279/Q:B = 0
2020 HGR2 : HCOLOR= 7
2022 HPLOT 0,0 TO 279,0
2024 HPLOT 0,25 TO 279,25
2026 HPLOT 0,50 TO 279,50
2030 FOR I = 1 TO Q
2050 FOR S = 1 TO C
2060 HPLOT B,191 TO B,191 -Z *R(I)
2135 HCOLOR= 2
2140 HPLOT B,25 -PH(I)
2150 B = B +1
2155 HCOLOR= 7
2160 NEXT S: NEXT I
2300 END
5000 END